﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using DataLayer.Repo;
using DataLayer.Types;

namespace ViewModel.Inventory
{
    public class ItemsListViewModel : WorkspaceViewModel
    {
        private ReadOnlyCollection<CommandViewModel> _commands;

        public ItemsListViewModel()
        {
//            _repository.DataChanged += _repository_DataChanged;
            _repository = new GenericRepository<InventoryItem>();
        }

        private GenericRepository<InventoryItem> _repository;

        private ObservableCollection<InventoryItem> inventoryItems;
        public ObservableCollection<InventoryItem> InventoryItems
        {
            get 
            { 
                return new ObservableCollection<InventoryItem>(_repository.FindAll());
            }
        }

        public ReadOnlyCollection<CommandViewModel> Commands
        {
            get
            {
                if (_commands == null)
                {
                    _commands = new ReadOnlyCollection<CommandViewModel>(CreateCommands());
                }
                return _commands;
            }
        }

        private IList<CommandViewModel> CreateCommands()
        {
            return new List<CommandViewModel>
                       {
                           new CommandViewModel("Properties", new RelayCommand(param => ShowItemPropertiesDialog())),
                           new CommandViewModel("New", new RelayCommand(param => ShowNewItemDialog()))
                       };
        }

        private void ShowNewItemDialog()
        {
        }

        private void ShowItemPropertiesDialog()
        {
        }
    }
}